package com.tx.main.zctest;

import com.tx.core.exceptions.util.AssertUtils;
import org.apache.commons.lang3.BooleanUtils;

import java.math.BigInteger;

/**
 * <pre>
 * 功能简述:
 * </pre>
 *
 * @author PengQingyang
 * 创建时间 [2024/3/27]
 */
public class Main2 {

    public static void main(String[] args) {
        //System.out.println(Long.parseLong("5.80E+03",16));
        //System.out.println((new BigDecimal("5.80E+03")).toBigInteger().toString());

        //System.out.println(hexToBOOLEAN1("0",3));

        //System.out.println(hexToBinaryOf16("1616"));
        //INTEGER16, BOOLEAN1, UNSIGNED16, UNSIGNED8, UNSIGNED32
        //System.out.println(StringUtils.substring(hexToBinaryOf16("1616"),0,8));
        //System.out.println(StringUtils.substring(hexToBinaryOf16("1616"),8,16));

        //String res = preProcess("0\n");
        //System.out.println(res);
        //System.out.println("");


        System.out.println( BooleanUtils.toBoolean("0"));
        System.out.println( BooleanUtils.toBoolean("1"));
    }

    /**
     * 预处理数据
     * @param cellData
     * @return
     */
    private static String preProcess(String cellData){
        AssertUtils.notEmpty(cellData,"cellData is empty.");

        return cellData.trim().replaceAll("\n","");
    }

    /**
     * 解析16进制数位32位无符号整形数据
     * @param cellData
     * @return
     */
    private static String hexToUNSIGNED32(String cellData) {
        BigInteger value = new BigInteger(cellData, 16);
        // 补充高位到32位
        return value.toString();
    }

    private static String hexToBOOLEAN1(String cellData,int cellDataIndex) {
        String binaryStr = hexToBinaryOf16(cellData);
        // 补充高位到32位
        Boolean b = Boolean.getBoolean("" + binaryStr.charAt(cellDataIndex));
        return b.toString();
    }

    private static String hexToBinaryOf16(String cellData) {
        BigInteger value = new BigInteger(cellData, 16);
        String binaryString = value.toString(10);
        //补充高位到16位
        return String.format("%16s", binaryString).replace(' ', '0');
    }


}
